|
|
|
|
|
|
|
Listing A.19. Coding the SQLdbOpen routine. |
|
|
|
|
|
|
|
|
Sub SQLdbOpen()
'
' open an existing database
'
On Error GoTo SQldbOpenErr
'
Dim strOpen As String
Dim intTemp As Integer
'
strLine = Trim(strLine) ' drop any spaces
intTemp = InStr(strLine, " ") ' locate first embedded space
strOpen = Mid(strLine, intTemp + 1, 255) ' get rest of line
'
' if line ends w/ ";", dump it!
If Right(strOpen, 1) = ";" Then
strOpen = Left(strOpen, Len(strOpen) - 1)
End If
'
' now try to open database
Set ws = DBEngine.CreateWorkspace("wsSQLVB", "admin", "")
Set db = ws.OpenDatabase(strOpen, False, False, strConnect)
strGlobalDBName = strOpen
intDBFlag = True
GoTo SQldbOpenExit
'
SQldbOpenErr:
ErrMsg Err, Error$, intLine, strLine, "SQldbOpen"
InitApp
'
SQldbOpenExit:
'
End Sub |
|
|
|
|
|
|
|
|
Listing A.19 performs three tasks. First, it strips the DBOPEN keyword off the script line. Second, if a semicolon (;) appears at the end of the line, the routine drops it. What's left is the valid database filename in the variable cOpen. The routine then attempts to open this file using the stored Connect string. Once that's done, the routine returns to SQLFileProcess. |
|
|
|
|
|
|
|
|
The next routine to add handles the DBCLOSE command. This is a simple routine. Its only job is to close the Microsoft Access Jet database. This routine also closes any open child forms and clears flag variables. Create a Public Sub called SQLdbClose and add the code in Listing A.20. |
|
|
|
|
|